import {iUseHttp, tHttp, tHttpRequest} from "plain-ui/src/packages/useHttp/useHttp.utils";
import {$http} from "../http";

const request: tHttpRequest = (config) => {
  return $http(config);
};

const http: tHttp = Object.assign(request, {
  get: (url: string, query: any, config: any) => $http.request({
    url,
    method: 'get',
    ...(config || {}),
    params: query,
  }) as any,
  post: (url: string, body: any, config: any) => $http.request({
    url,
    data: body,
    method: 'post',
    ...config,
  }) as any,
  put: (url: string, body: any, config: any) => $http.request({
    url, data: body,
    method: 'put',
    ...config,
  }) as any,
  delete: (url: string, body: any, config: any) => $http.request({
    url, data: body,
    method: 'delete',
    ...config,
  }) as any,
});


export const useHttp: iUseHttp = () => http;
